<?php

/**
 * Shop form base class.
 *
 * @method Shop getObject() Returns the current form's model object
 *
 * @package    tsantek-shop
 * @subpackage form
 * @author     Tomislav Šantek
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseShopForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'              => new sfWidgetFormInputHidden(),
      'is_active'       => new sfWidgetFormInputCheckbox(),
      'domain'          => new sfWidgetFormInputText(),
      'custom_layout'   => new sfWidgetFormInputCheckbox(),
      'show_global'     => new sfWidgetFormInputCheckbox(),
      'pg_class_id'     => new sfWidgetFormInputText(),
      'pg_mch_code'     => new sfWidgetFormInputText(),
      'pg_signing_key'  => new sfWidgetFormInputText(),
      'name'            => new sfWidgetFormInputText(),
      'company_name'    => new sfWidgetFormInputText(),
      'description'     => new sfWidgetFormTextarea(),
      'location_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Location'), 'add_empty' => false)),
      'contact_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Contact'), 'add_empty' => false)),
      'pic_path'        => new sfWidgetFormInputText(),
      'tax'             => new sfWidgetFormInputText(),
      'tax_included'    => new sfWidgetFormInputCheckbox(),
      'delivery_time'   => new sfWidgetFormInputText(),
      'account_number'  => new sfWidgetFormInputText(),
      'order_id_tpl'    => new sfWidgetFormInputText(),
      'order_counter'   => new sfWidgetFormInputText(),
      'invoice_id_tpl'  => new sfWidgetFormInputText(),
      'invoice_counter' => new sfWidgetFormInputText(),
      'slug'            => new sfWidgetFormInputText(),
      'created_at'      => new sfWidgetFormDateTime(),
      'updated_at'      => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'              => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'is_active'       => new sfValidatorBoolean(array('required' => false)),
      'domain'          => new sfValidatorString(array('max_length' => 255)),
      'custom_layout'   => new sfValidatorBoolean(array('required' => false)),
      'show_global'     => new sfValidatorBoolean(array('required' => false)),
      'pg_class_id'     => new sfValidatorString(array('max_length' => 20, 'required' => false)),
      'pg_mch_code'     => new sfValidatorString(array('max_length' => 20, 'required' => false)),
      'pg_signing_key'  => new sfValidatorString(array('max_length' => 20, 'required' => false)),
      'name'            => new sfValidatorString(array('max_length' => 255)),
      'company_name'    => new sfValidatorString(array('max_length' => 255)),
      'description'     => new sfValidatorString(array('max_length' => 2000)),
      'location_id'     => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Location'))),
      'contact_id'      => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Contact'))),
      'pic_path'        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'tax'             => new sfValidatorNumber(array('required' => false)),
      'tax_included'    => new sfValidatorBoolean(array('required' => false)),
      'delivery_time'   => new sfValidatorString(array('max_length' => 100, 'required' => false)),
      'account_number'  => new sfValidatorString(array('max_length' => 18, 'required' => false)),
      'order_id_tpl'    => new sfValidatorString(array('max_length' => 30, 'required' => false)),
      'order_counter'   => new sfValidatorInteger(array('required' => false)),
      'invoice_id_tpl'  => new sfValidatorString(array('max_length' => 30, 'required' => false)),
      'invoice_counter' => new sfValidatorInteger(array('required' => false)),
      'slug'            => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'created_at'      => new sfValidatorDateTime(),
      'updated_at'      => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'Shop', 'column' => array('name'))),
        new sfValidatorDoctrineUnique(array('model' => 'Shop', 'column' => array('domain'))),
        new sfValidatorDoctrineUnique(array('model' => 'Shop', 'column' => array('slug'))),
        new sfValidatorDoctrineUnique(array('model' => 'Shop', 'column' => array('slug'))),
      ))
    );

    $this->widgetSchema->setNameFormat('shop[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Shop';
  }

}
